<?php

/*
 * bdd-salaries/load-index.phtml
 */
?>

<?php if(!(count($employeList))): ?>        
    <div class=''>Aucun salarié ne correspond au critère de recherche!</div>
<?php else :?>        
    <div class="list-container list-employe">


        <table class="table table-striped list-table">
            <thead>
                <tr> 
                    <?php 
                            $isOrderDescByNom = $orderCol === 'nom1';
                            $isOrderDescByPrenom = $orderCol === 'prenom';                    
                            $isOrderDescByMatr = $orderCol === 'matricule';                    
                    ?>
                    <td width="10%"><a href='' class='order-by' data-order-state='<?php echo $orderColState ;?>' data-witch='matricule'>Matricule<i class="icon-chevron-<?php echo $isOrderDescByMatr ?  ($orderColState === 'asc'? 'down' : 'up' ): '' ;?>"></i> </a> </td>                                        
                    <td width="25%"><a href='' class='order-by' data-order-state='<?php echo $orderColState ;?>' data-witch='nom1'>Nom<i class="icon-chevron-<?php echo $isOrderDescByNom  ?  ($orderColState === 'asc'? 'down' : 'up' ) : '' ;?>"></i> </a></td>            
                    <td width="25%"><a href='' class='order-by' data-order-state='<?php echo $orderColState ;?>' data-witch='prenom'>Prénom <i class="icon-chevron-<?php echo $isOrderDescByPrenom ? ($orderColState === 'asc'? 'down' : 'up' ) : '' ;?>"></i> </td>            
                    <td width="25%">Poste</td>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($employeList as $emp): ?>
                   
                    <?php
                        //var_dump($emp); die;
                        $poste	 = $emp->getPoste();
                        $avenant = $emp->getAvenant();
                    ?>
                <tr class="tr-employe" onclick="return changeLocationToFiche(<?php echo $emp->matricule ;?>);"  >
                    <td style="text-align: center;"><?php echo $emp->getMatricule(true); ?></td>
                    <td style="text-align: center;"><?php echo $emp->nom1; ?></td>
                    <td style="text-align: center;"><?php echo $emp->prenom; ?></td>
                    <td style="text-align: center;"><?php echo $poste->code; ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="7" style="text-align: center;">
                        <?php if ($nbPage > 1):?>
                            <?php if ($page == 1): ?>
                            <?php else: ?>
                                <a href="#" class="navigate-page navigate-left" data-page="1"></a>
                            <?php endif; ?>

                            <?php for ($i = 1; $i <= $nbPage; $i++): ?>
                                <?php if ($page == $i): ?>
                                    <?php echo $i; ?> &nbsp; - &nbsp;
                                <?php else: ?>
                                    <a href="#" class="navigate-page" data-page="<?php echo $i; ?>"><?php echo $i; ?></a> &nbsp; - &nbsp;
                                <?php endif; ?>
                            <?php endfor; ?>
                            <?php if ($page == $nbPage): ?>
                            <?php else: ?>
                                    <a href="#" class="navigate-page navigate-right" data-page="<?php echo $nbPage; ?>"></a>
                            <?php endif; ?>
                       <?php else :?>
                             &nbsp;
                       <?php endif; ?>
                    </td>
                </tr>
            </tfoot>
        </table>

    </div>
<?php endif ;?>

<script type="text/javascript">
    
        <?php if(!(count($employeList))): ?>
           

        <?php else :?>
             function changeLocationToFiche(matricule){
                 var motif = "<?php  echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'edit', 'id'		 => 0)) ?>";
                 url = motif.replace('0', matricule);
                 //window.location = url;
                 window.open(url);
                 return true;
             }
             
             $('.navigate-page').click(function(e){
                e.preventDefault();
                page = $(this).attr('data-page');
                //$('#data-page').val(page);
                refresh({page: page});
            });
            
            $('.order-by').click(function(e){
                e.preventDefault();
                
                orderState = $(this).attr('data-order-state');    
                witchElt =  $(this).attr('data-witch') ;
                inversedOrderState = orderState === 'desc'? 'asc' : 'desc'; 
                
                $('#data-col-order').val(witchElt);
                $('#data-col-order-state').val(inversedOrderState);
                   
                page = $(this).attr('data-page');
                refresh({page: page});
                //console.log(orderState);
            });
            
           
        <?php endif ;?>
    
</script>
